package oop.data;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;
import java.util.Map;

import oop.db.dao.ExaminationDAO;
import oop.db.dao.MarkChoiceDAO;
import oop.db.dao.TestVersionDAO;

public class Mark {
 
	private long id;
	private long examinationId;
	private long testVersionId;
	private String studentName;
	private String studentSurname;
	private String studentId;
	private Date studentBirthday;
	private double mark;
	private Map<Long, List<Long>> choices;

	public Mark(long id, long testVersionId, String studentName,
			String studentSurname, String studentId, Date studentBirthday,
			double mark, long examinationId) {
		super();
		this.id = id;
		this.testVersionId = testVersionId;
		this.studentName = studentName;
		this.studentSurname = studentSurname;
		this.studentId = studentId;
		this.studentBirthday = studentBirthday;
		this.mark = mark;
		this.examinationId = examinationId;
	}

	public String getStudentName() {
		return studentName;
	}

	public void setStudentName(String studentName) {
		this.studentName = studentName;
	}

	public String getStudentSurname() {
		return studentSurname;
	}

	public void setStudentSurname(String studentSurname) {
		this.studentSurname = studentSurname;
	}

	public String getStudentId() {
		return studentId;
	}

	public void setStudentId(String studentId) {
		this.studentId = studentId;
	}

	public Date getStudentBirthday() {
		return studentBirthday;
	}

	public void setStudentBirthday(Date studentBirthday) {
		this.studentBirthday = studentBirthday;
	}

	public long getId() {
		return id;
	}

	public TestVersion getTestVersion() throws SQLException {
		return TestVersionDAO.fetchById(testVersionId);
	}
	
	public void setTestVersion(TestVersion version) {
		this.testVersionId = version.getId();
	}

	public double getMark() {
		return mark;
	}
	
	public void setMark(double mark) {
		this.mark = mark;
	}

	public Examination getExamination() {
		try {
			return ExaminationDAO.fetchById(examinationId);
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}
	
	public Map<Long, List<Long>> getChoices() throws SQLException {
		if (choices == null) {
			choices = MarkChoiceDAO.fetchChoices(id);
		}
		return choices;
	}
	
}
